<!-- <template>

 <addRess :bagcolor="1"></addRess>
</template>
<script>
	import addRess from "../../components/address/index.vue";
	export default {
		data() {
			return {
				 checkboxItems: [{
				          name: 'USA',
				          value: '美国'
				        },
				        {
				          name: 'CHN',
				          value: '中国',
				          checked: 'true'
				        }
				        ],
			}
		},
		methods: {
			
			topage() {
				uni.navigateTo({
					url: '/subPages/mine/addAdress'
				})
			},
		
		},
		components:{
			addRess
		}
		
	}

</script>

<style lang="scss" scoped></style> -->



<template>
    <view :class="bagcolor==1? 'content-header' : 'active' ">
    	<view class="title-name">
    		请选择收货地址
    	</view>
    	<view class="selected-address">
    		<radio-group @change="radioChange">
    			<view class="selected-item" v-for="(item,index) in addressList">
    			
    					 <radio class="checkbox" :checked="index==current"  :value="item.id"></radio>  
    					<text style="margin-right: 26rpx;">{{item.name}}</text><text>{{item.phone}}</text>
    					<view class="item-address">
    						{{item.province + item.city + item.district + item.addressDetail}}
    					</view>
    				
    				<view class="operate">
    				    <view style="position: absolute; right: 80rpx; top: 0; color:red;"
    				        @click.stop="deletFun(item.id)">删除</view>
    				    <view style="position: absolute; right: 0; top: 0; color:#1677FF;"
    				        @click.stop="topage(item.id)">编辑</view>
    				</view>
    			</view>
    		</radio-group>
    	</view>
    	 <view class="addAdress">	
    	   <u-icon name="plus-circle" size="20"></u-icon>
    	<text style="margin-left:16rpx;" @click="topage()">新增地址</text>
    	 </view>
    
    </view>

</template>

<script>
    import address from "@/api/address.js";
    export default {
        data() {
            return {
                addressList: [],
                addressLis: [{
                        id: "1",
                        name: "张三",
                        phone: "15678094125",
                        address: " 湖北省武汉市洪山区关山大道花园小区"
                    },
                    {
                        id: "2",
                        name: "李四",
                        phone: "15678094125",
                        address: " 湖北省武汉市洪山区关山大道花园小区"
                    },
                    {
                        id: "3",
                        name: "王五",
                        phone: "15678094125",
                        address: " 湖北省武汉市洪山区关山大道花园小区"
                    }
                ],
                current: 1 //默认选中的值
            }
        },


        mounted() {
            this.getAddressList();
        },
        methods: {
            getAddressList() {
          
                address.addressList().then((res) => {
                    console.log("res=>", res);
                    if (res.code == 200) {
                        this.addressList = res.rows;
						console.log(res.rows)
                    }
                }).catch((erro) => {
                    console.log("error")
                });
            },

            handleTriggerSelect(item) {
                if (item.isDefault == 0) {
                    uni.showToast({
                        title: "该地址已是默认地址",
                        icon: "none",
                    });
                    return;
                }
                let params = {
                    ...item,
                    isDefault: 0,
                };
                address.updateAddress(params).then((res) => {
                    if (res.code == 200) {
                        uni.showToast({
                            title: "修改成功",
                            icon: "none",
                        });
                        this.getAddressList();
                    }
                });
            },
            deletFun(ids) {
              
                address.deleteAddressIds(ids).then((res) => {
                    console.log(res);
                    if (res.code == 200) {
                        uni.showToast({
                            title: "删除成功",
                            icon: "none",
                        });
                        this.getAddressList();
                    }
                });
            },
            topage(id) {
                console.log(id, "id====");
                if (id) {

                    uni.navigateTo({
                        url: "/subPages/mine/addAdress?id=" + id,
                    });
                } else {
                    uni.navigateTo({
                        url: '/subPages/mine/addAdress',
                    });
                }
            },
            radioChange(event) {
              console.log(event.detail.value);
            },
        },
        onShow() {
            this.getAddressList();

        },
        props: ['bagcolor'],

        // mounted() {
        // console.log(this.bagcolor);
        // },
        onLoad() {
            this.getAddressList();
        },

    }
</script>

<style lang="scss" scoped>
    .content-header {
        box-sizing: border-box;
        padding-left: 32rpx;
        padding-right: 32rpx;


    }

    .active {
        background-color: #F8F9FF;
        border-radius: 25rpx;
        box-sizing: border-box;
        padding: 30rpx;

    }

    .title-name {
        font-size: 32rpx;
        color: #333333;
        font-weight: 600;
        margin: 32rpx 0;
        margin-left: 16rpx;
    }

    .selected-address {
        width: 100%;
    }

    .item-address {
        width: 398rpx;
        margin-left: 62rpx;
        color: #777777;

    }

    .selected-item {
        width: 100%;
        margin: 38rpx 0;
        font-size: 30rpx;
        position: relative;

    }

    .checkbox {
        margin-right: 14rpx;
        margin-top: 16rpx;

    }

    .addAdress {
        color: #777777;
        display: flex;
    }
</style>